﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using DataObjectsPhone;
using System.Device.Location;
using Microsoft.Phone.Controls.Maps;
using Microsoft.Phone.Controls.Maps.Platform;

namespace ee_wp_tourmaker.Views
{
    public partial class ChallengeCheckPointsMap : PhoneApplicationPage
    {
        public ChallengeCheckPointsMap()
        {
            InitializeComponent();
        }

        private void BingMap_Loaded(object sender, RoutedEventArgs e)
        {
            Challenge content = App.MainModel.SelectedChallenge;

            foreach (CheckPoint checkpoint in content.checkpointsList)
            {
                Location l = new GeoCoordinate((double)checkpoint.Latitude, (double)checkpoint.Longitude);
                Pushpin pin = new Pushpin();
                if (checkpoint.Done)
                {
                    pin.Background = new SolidColorBrush(Colors.Green);
                }
                else
                {
                    pin.Background = new SolidColorBrush(Colors.Red);
                }


                pin.Location = l;
                BingMap.Children.Add(pin);
            }
            
            var latinude = content.checkpointsList.Sum(q => q.Latitude) / content.checkpointsList.Count;
            var longitude = content.checkpointsList.Sum(q => q.Longitude) / content.checkpointsList.Count;
            BingMap.SetView(new GeoCoordinate((double)latinude, (double)longitude), 12);                
               
        }

        }


    }
